uniform sampler2D tex;
uniform vec2 targetPosition;
uniform float targetRadius;

varying vec4 vTexCoord;
varying vec4 vColour;

void main()
{
    // Get distance from fragment position to target and calculate blend based on that.
    float dist = length(targetPosition - gl_FragCoord);
    float colourScale = 1.0;
    
    if (dist <= targetRadius)
    {
        // Convert to angle between 0 and 90.
        colourScale = 1.0 - cos(dist * 3.14159 / (targetRadius * 2.0));
    }
    
    vec4 texColour = vec4(texture2D(tex, vTexCoord.xy));
    vec4 finalColour = vec4(mix(1.0, texColour.x, colourScale), texColour.yzw);
    
    gl_FragColor = finalColour;
}
